function UpdateCriteriaLevel3Order() {
    var criteriaLevel2List = db.CriteriaLevel2.find({})
    criteriaLevel2List.forEach(function (doc) {
        ReverseOrder(doc._id);
    });
}

function ReverseOrder(CriteriaLevel2Id)
{
    var index = 1;
    db.CriteriaLevel3.find({CriteriaLevel2Id: CriteriaLevel2Id}).sort({Order:-1}).forEach(
    function (e) 
    {
        e.Order = parseInt(index);
        index = index + 1;
        db.CriteriaLevel3.save(e);
    })
}

UpdateCriteriaLevel3Order();  
